//
//  newestCell.m
//  A Learning Walk
//
//  Created by dllo on 16/6/15.
//  Copyright © 2016年 战斗民族. All rights reserved.
//

#import "newestCell.h"
#import "UILabel+LeftTopAlign.h"
@interface newestCell ()

@property(nonatomic, retain)UIImageView *imageV;
@property(nonatomic, retain)UILabel *titleLabel;
@property(nonatomic, retain)UILabel *timeLabel;
@property(nonatomic, retain)UILabel *replyLabel;

@end

@implementation newestCell

-(void)dealloc{
    [_carModel release];
    [_Model release];
    [_newsestmodel release];
    [_imageV release];
    [_timeLabel release];
    [_titleLabel release];
    [_replyLabel release];
    [super dealloc];

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)createSubviews{
    self.imageV = [UIImageView new];
    self.imageV.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.imageV];
    
    self.timeLabel = [UILabel new];
    self.timeLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.timeLabel];

    self.titleLabel = [UILabel new];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.numberOfLines = 2;
    [self.titleLabel sizeToFit];
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.titleLabel UILabelLeftTopAlign];//左上方法

    
    self.replyLabel = [UILabel new];
    self.replyLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.replyLabel];
    
    self.myView = [UIView new];
    self.myView.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.myView];
    
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@15);//上
        make.bottom.equalTo(@(-10));//下
        make.left.equalTo(@15);//左
        make.width.equalTo(@100);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageV);
        make.height.equalTo(@60);
        make.right.equalTo(@(-30));
        make.left.equalTo(self.imageV.mas_right).with.offset(10);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.imageV);
        make.left.equalTo(self.imageV.mas_right).with.offset(10);
        make.height.equalTo(@25);
        make.width.mas_equalTo(self.contentView.frame.size.width / 3);
    }];
    [self.replyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.imageV);
        make.height.equalTo(self.timeLabel);
        make.right.equalTo(@(-15));
    }];
    [self.myView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-1);
        make.left.mas_equalTo(self.imageV);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(1);        
    }];

}




-(void)setNewsestmodel:(newestModel *)newsestmodel{
    _newsestmodel = newsestmodel;
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:_newsestmodel.smallpic] placeholderImage:[UIImage imageNamed:@"NOImage"]];
    self.titleLabel.text = _newsestmodel.title;
    self.timeLabel.text = _newsestmodel.time;
    switch (_newsestmodel.mediatype) {
        case 1:
            self.replyLabel.text = [[NSString stringWithFormat:@"%ld",(long)_newsestmodel.replycount] stringByAppendingString:@"评论"];
            break;
        case 2:
            self.replyLabel.text = [[NSString stringWithFormat:@"%ld",(long)_newsestmodel.replycount] stringByAppendingString:@"评论"];
            break;
        case 3:
            self.replyLabel.text = [[NSString stringWithFormat:@"%ld",(long)_newsestmodel.replycount] stringByAppendingString:@"播放"];
            break;
        case 4:
            self.replyLabel.text = [[NSString stringWithFormat:@"%ld",(long)_newsestmodel.replycount] stringByAppendingString:@"浏览"];
            break;
        case 5:
            self.replyLabel.text = [[NSString stringWithFormat:@"%ld",(long)_newsestmodel.replycount] stringByAppendingString:@"回帖"];
            break;
            
        default:
            break;
    }

}

-(void)setModel:(newsModel *)Model{
    _Model = Model;
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:_Model.smallpic] placeholderImage:[UIImage imageNamed:@"NOImage"]];
    self.titleLabel.text = _Model.title;
    self.timeLabel.text = Model.time;
    //NSLog(@"%ld",Model.replycount);
    self.replyLabel.text = [[NSString stringWithFormat:@"%ld",(long)_Model.replycount] stringByAppendingString:@"评论"];
}


-(void)setCarModel:(carsModel *)carModel{
    _carModel = carModel;
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:_carModel.smallpic] placeholderImage:[UIImage imageNamed:@"NOImage"]];
    self.titleLabel.text = _carModel.title;
    self.timeLabel.text = _carModel.time;
    //NSLog(@"%ld",Model.replycount);
    self.replyLabel.text = [[NSString stringWithFormat:@"%ld",(long)_carModel.replycount] stringByAppendingString:@"评论"];
}



@end
